<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript">
{
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<?php
$u=$_SESSION['username'];
?>
<?php
include("conf/dbconect.php");
?>
<?php
  $sql="select * from thanhvien where username='$u'";
  $result=mysql_query($sql);
  $rows=@mysql_fetch_array($result);
  $v=$rows['vpoint'];
?>
<?php

if(isset($_POST['btndangtin']))
{   if ($v < 15) 
      {
            ?>
              <script language="javascript">
                window.alert('Đã hết Vpoint, hãy nạp thêm để đăng tin');
                window.location="index.php?left=16";
              </script><?php
      }
    else
    {
          $vi=$rows['vpoint']-15;
          $td=$_POST['txttieude'];
          $d=$_POST['txtdientich'];
          $g=$_POST['txtgiaphong'];
          $dc=$_POST['txtdiachi'];
          $m=$_POST['editor1'];
          $t=$_POST['cbtinh'];
          include('conf/dbconect.php');
          $sql="INSERT INTO baidang(tieude,dientich,giaphong,diachi_tin,tinh,mota,nguoidang) values('$td','$d','$g','$dc','$t','$m','$u')";
          $sql2="UPDATE thanhvien set vpoint=$vi";
          $result=mysql_query($sql);
          $result2=mysql_query($sql2);
            if($result & $result2)
            {
              
              {
              ?>
                      <script language="javascript">
                window.alert('Đăng tin thành công');
                window.location="index.php";
                      </script>
                      <?php
              }
              ?>
              <script language="javascript">
                window.alert('Đăng tin thành công');
                window.location="index.php";
                      </script>
            <?php
            }
          else
          {
            echo' Đăng tin thất bại:'.mysql_error();
          }
    }
}
?>
<div id="dangtin">
  <h2>ĐĂNG TIN MỚI</h2> <hr/>
	<form action="" name="frmdangtin" method="post" onSubmit="return checkInput();" enctype="multipart/form-data">
		<table border="1" width="500" style="width:100%">
			<tr>
				<td align="right" style="background:#99FFFF"><b>Tiêu đề:<font color="#DD0000">*</font></b></td>
				<td style="background:#CCFFFF"><input type="text" name="txttieude" id="txttieude" placeholder="Nhập tiêu đề" size="80"> </td>
			</tr>

			<tr>
				<td align="right" style="background:#99FFFF"><b>Diện tích:<font color="#DD0000">*</font></b></td>
				<td style="background:#CCFFFF"><input type="text" name="txtdientich" id="txtdientich" placeholder="Nhập diện tích" size="80"> m<sup>2</sup></td>
			</tr>

			<tr>
				<td align="right" style="background:#99FFFF"><b>Giá phòng:<font color="#DD0000">*</font></b></td>
				<td style="background:#CCFFFF"><input type="text" name="txtgiaphong" id="txtgiaphong" placeholder="Nhập giá phòng" size="80"> VNĐ</td>
			</tr>

			<tr>
				<td align="right" style="background:#99FFFF"><b>Địa chỉ:<font color="#DD0000">*</font></b></td>
				<td style="background:#CCFFFF"><input type="text" name="txtdiachi" id="txtdiachi" placeholder="Nhập địa chỉ" size="80"></td>
			</tr>
      <tr>
        <td align="right" style="background:#99FFFF"><b>Tỉnh thành<font color="#DD0000">*</font></b></td>
        <td style="background:#CCFFFF">
          <select name="cbtinh">
            <option value="" style="width: 170px" selected="selected">--Chọn tỉnh thành--</option>
            <?php
              require_once('conf/dbconect.php');
              $sql="select * from menutinhthanh";
              $result=mysql_query($sql);
              while($rows=@mysql_fetch_array($result))
              {
            ?>  
            <option value="<?php echo $rows['tentinhthanh'] ;?>"><?php echo $rows['tentinhthanh'] ;?></option>
              <?php 
              }
            ?>
          </select>
        </td>
      </tr>
			<tr>
				<td align="right" style="background:#99FFFF"> <b>Mô tả chi tiết:<font color="#DD0000">*</font></b></td>
				<td style="background:#CCFFFF"><textarea class="ckeditor" id="editor1" rows="20" cols="65" name="editor1"></textarea></td>
			</tr>

			<tr>
				<td colspan="2"> <center><input type="submit" value="ĐĂNG TIN" name="btndangtin">
				<input type="reset" value="NHẬP LẠI" name="btnnhaplai"></center></td>
			</tr>
		</table>
	</form>
</div>
  <script language="javascript" type="text/javascript">
    CKEDITOR.replace('editor1',{
      filebrowserBrowseUrl: 'browser/browse.php',
      filebrowserImageBrowseUrl: 'browser/browse.php?type=Images',
      filebrowserUploadUrl: 'uploader/upload.php',
      filebrowserImageUploadUrl: 'uploader/upload.php?type=Images',
      filebrowserWindowWidth: '900',
      filebrowserWindowHeight: '400',
      filebrowserBrowseUrl: 'ckfinder/ckfinder.html',
      filebrowserImageBrowseUrl: 'ckfinder/ckfinder.html?Type=Images',
      filebrowserFlashBrowseUrl: 'ckfinder/ckfinder.html?Type=Flash',
      filebrowserUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
      filebrowserImageUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
      filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
  </script>